1. Field of the Invention
The present invention relates to the computer graphics technology, and more particularly to a method and apparatus for rendering a computer graphic primitive intersected with user-defined clipping planes.
2. Description of the Prior Art
The essential operations of three-dimensional (“3-D”) computer graphics concern the generation, or rendering, of two-dimensional (“2-D”) images of 3-D objects for display or presentation onto a display device or monitor, such as a Cathode Ray Tube (CRT) or a Liquid Crystal Display (LCD). The object may be a simple geometry primitive such as a point, a line segment, a triangle, or a polygon. More complex objects can be rendered onto a display device by representing the objects with a series of connected planar polygons, such as, for example, by representing the objects as a series of connected planar triangles. All geometry primitives may eventually be described in terms of one vertex or a set of vertices, for example, coordinate (x, y, z) that defines a point, for example, the endpoint of a line segment, or a corner of a triangle.
To generate a data set for display as a 2-D projection representative of a 3-D primitive onto a computer monitor or other display device, the vertices of the primitive are processed through a series of operations, or processing stages in a graphics-rendering pipeline. A generic pipeline is merely a series of cascading processing units, or stages, in which the output from a prior stage serves as the input for a subsequent stage. In the context of a graphics processor, these stages include, for example, pervertex operations, primitive assembly operations, pixel operations, texture assembly operations, rasterization operations, and fragment operations.
In a typical graphics display system, the objects are described with a number of small polygons, generally referred to as graphics primitives, which cover the surface of the object in the same manner that a number of small tiles can cover a wall or other surface. Each polygon is described as a list of vertex coordinates (X, Y, Z in “Model” coordinates) and some specification of material surface properties (i.e., color, texture, shininess, etc.). For three-dimensional objects with complex curved surfaces, the polygons in general must be triangles or quadrilaterals, and the latter can always be decomposed into pairs of triangles.
A transformation engine transforms the object coordinates in response to the angle of viewing selected by a user from user input. In addition, the user may specify the field of view, the size of the image to be produced, and the back end of the viewing volume so as to include or eliminate background as desired.
Once this viewing area has been selected, clipping logic, such as the scissor window, eliminates the graphics primitives (i.e., triangles) which are outside the viewing area and “clips” the graphics primitives which are partly inside and partly outside the viewing area. These clipped graphics primitives will correspond to the portion of the graphics primitives inside the viewing area with new edge(s) corresponding to the edge(s) of the viewing area. The vertices of the resulting graphics primitives are then transmitted to the next stage in coordinates corresponding to the viewing screen (in X, Y coordinates) with an associated depth for each vertex (the Z coordinate). In a typical system, the lighting model is next applied taking into account the light sources. The graphics primitives with their color values are then transmitted to the pixel interpolation module (or referred to as the attribute interpolation module), such as a rasterizer.
For each graphics primitive, the rasterizer determines which pixel positions the graphics primitive and attempts to write the associated color values and depth (Z value) into frame buffer cover. The rasterizer compares the depth values (Z) for the graphics primitive being processed with the depth value of a pixel, which may already be written into the frame buffer. If the depth value of the new graphics primitive pixel is smaller, indicating that it is in front of the primitives already written into the frame buffer, then its value will replace the value in the frame buffer because the new graphics primitive will obscure the graphics primitive previously processed and written into the frame buffer. This process is repeated until all of the graphics primitives have been rasterized. At that point, a video controller displays the contents of a frame buffer on a display a scan line at a time in raster order.
With this general background provided, reference is now made to FIG. 1, which shows a block diagram of a conventional pipelined computer graphics primitive rendering apparatus 100. The input data including the graphics primitive PR and the clipping logic CLogic is passed through the pipeline. The graphics primitive PR may include the location data (for example, vertices represented as spatial coordinates X, Y, Z). On the other hand, the clipping logic CLogic may include the default scissor window as well as one or more user-defined clipping planes UDCPs. The scissor window is usually represented as four boundary values, i.e., the values of the top, bottom, left and right boundaries of the viewing area The clipping plane UDCP may be represented as a space coordinate function, for example, f(X,Y,Z)=aX+bY+cZ+d. Particularly, the clipping plane UDCP may be configured to clip (i.e., removes) those pixels or points in the graphics primitives PR making the function f(X,Y,Z) negative and only allow those pixels or points making the function f(X,Y,Z) positive to show. The function f(X,Y,Z) representing the clipping plane will be hereinafter referred to as the clipping plane function.
The input data (PR+CLogic) enters the vertex shader 102 first. The vertex shader 102 may perform various transformations on the vertices data of the graphics primitive PR. For example, the vertices data may be transformed from World coordinates into Model View coordinates, into Projection coordinates, and ultimately into Screen coordinates. The vertex shader 102 may also calculate or retrieve attributes of vertices of the graphics primitive PR, such as color and perspective correction factor (in the figure, VX_ATT represents the set comprising all such attributes). When the user defined clipping plane UDCP is included in the input data, the vertex shader 102 could also calculate the clipping judgment distances between the vertices of graphic primitives PR and the clipping plane UDCP (in the figure, VX_DISc represents the set comprising the clipping judgment distances for all vertices). Outcome of the clipping function f(X,Y,Z) with its input parameters set to the coordinate of a vertex may be used as the clipping judgment distance between the vertex and the clipping plane UDCP represented by the clipping function f(X,Y,Z). When the clipping judgment distance between a vertex and the clipping plane UDCP is negative, the vertex may be clipped and skipped in primitive displaying process; otherwise, i.e., when the distance is positive, the vertex may be shown.
Based on the output from the vertex shader 102, the pixel interpolation module 106 calculates all pixels PX contained in the graphics primitive PR and the attributes PX_ATT thereof, as well as the clipping judgment distances PX_DISc between all pixels PX and the clipping plane UDCP. Thereafter, a Z-test is performed in the Z-test module 108 on each pixel within the graphics primitive PR being operated upon. As is known, comparing a current Z-value (i.e., the depth value for a given pixel of the current graphics primitive PR) with a stored Z-value (stored in the buffer generally referred to as the Z buffer) for the corresponding pixel location performs the so-called Z-test. The stored Z-value provides the depth value for a previously rendered primitive for a given pixel location. If the current Z-value is not closer to the current viewpoint than the stored Z-value, then neither the frame buffer nor Z-buffer contents need to be replaced, as a previously rendered pixel will be deemed to be in front of the current pixel. If the current Z-value indicates a depth that is closer to the viewer's eye than the stored Z-value, then the current Z-value will replace the stored Z-value and the current graphic information (i.e., color) will replace the color information in the corresponding frame buffer pixel location (as determined by the pixel shader 110). The Z test module will read from the Z buffer all the pixels PXz passing the Z test. For pixels within the graphics primitive that are rendered and determined to be closer to the viewpoint than previously-stored pixels, information relating to the graphics primitive is passed on to the pixel shader 110 which determines color information for each of the pixels within the graphics primitive that are determined to be closer to the current viewpoint. Besides, the conventional computer graphics primitive rendering apparatus 100 may also include a color reading module 112 which reads color and transparency information used by the background presentation processing for the graphics primitive PR.
In regard to the situation with user defined clipping plane, the pixel shader 110 of the conventional computer graphics primitive rendering apparatus 100 processes the group of pixels PXz passing the Z test, removes the pixels with negative clipping judgment distances PXz_DISc, and outputs the actually rendered pixels PXr. However, all the clipping judgment distances of all the pixels PX in the graphics primitive PR may be completely determined in the pixel interpolation module 106. The process of the Z test module 108 does not reference the user defined clipping planes and related information, and thus wastes a lot of calculation and memory bandwidth in the Z testing on already clipped pixels. Furthermore, the pixel interpolation module 106 also wastes too many efforts on getting pixel attributes and calculating the clipping judgment distances of all pixels in the current graphics primitive PR. Some pixels in the graphics primitive PR may be removed in the phase of attribute interpolation.
In view of the foregoing disadvantages of the prior art, there is a need to provide an improvement to avoid system resource wasting and redundant calculation. It is also desirable that the whole performance can be enhanced but the original structure of the conventional computer graphics primitive rendering apparatus is not altered, so that the entire cost may be minimized.